<template>
  <div class="dashboard-container">
    <div style="display: flex;height: 400px;">
      <el-card style="width: 50%;">
        <div id="playerSpread" style="width: 500px;height:400px;"></div>
      </el-card>
      <el-card style="width: 50%;">
        <div id="pie1" style="width: 500px;height:400px;"></div>
      </el-card>
    
    </div>


  </div>
  
</template>

<script>
import echarts from 'echarts'
import playerApi from '@/api/player/player'
import honorApi from '@/api/honor/honor'
import { mapGetters } from 'vuex'


export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  created() {
    
  },
  mounted() {
    this.showChart()
  },
  
  methods: {
    showChart(){
      playerApi.getPlayerSpread()
      .then((response) => {
        this.setPlayerSpreadData(response.data)
      })
      honorApi.getClueHonor()
      .then((response) =>{
        this.setClueHonorData(response.data)
      })
    },
    setClueHonorData(clueHonorData){
      var myChart2 = echarts.init(document.getElementById('pie1'))
      var clueHonor = {
        title: {
          text: '战队荣誉图',
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: clueHonorData
          }
        ]
      };
      myChart2.setOption(clueHonor)
    },
    setPlayerSpreadData(playerSpreadData){
      console.log(document.getElementById('playerSpread'))
      // 基于准备好的dom，初始化echarts实例
      var myChart1 = echarts.init(document.getElementById('playerSpread'))
      
      var playerSpread = {
        title: {
          text: '选手分布图',
          subtext: 'Fake Data',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            // name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: playerSpreadData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
      
      // 使用刚指定的配置项和数据显示图表。
      myChart1.setOption(playerSpread)
      
      },
    }

}
</script>

<!-- <style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style> -->
